package b_Stack;

import c_LinkedList.LinkedList;

public class LinkedListStack<E> implements Stack<E>{

	private LinkedList<E> linkedList;
	
	public LinkedListStack() {
		linkedList=new LinkedList<>();
	}
	
	@Override
	public void push(E e) {
		linkedList.addFirst(e);
	}

	@Override
	public E pop() {
		return linkedList.removeFirst();
	}

	@Override
	public E peek() {
		return linkedList.getFirst();
	}

	@Override
	public int getSize() {
		return linkedList.getSize();
	}

	@Override
	public boolean isEmpty() {
		return linkedList.isEmpty();
	}
	
	@Override
	public String toString() {
		StringBuilder result=new StringBuilder();
		result.append("Stack:top [");
	    for(int i=0;i<linkedList.getSize();i++) {
	    	if(i!=0)
	    		result.append(", ");
	    	result.append(linkedList.getIndex(i));
	    }
	    result.append("]");
		return result.toString();
	}
	
	public static void main(String[] args) {
		LinkedListStack<Integer> linkedListStack=new LinkedListStack<>();
		for(int i=0;i<6;i++) {
		linkedListStack.push(i);
		System.out.println(linkedListStack);
		}
		
		int a=linkedListStack.pop();
		System.out.println(a);
		System.out.println(linkedListStack.peek());
		
		
	}

}
